library(tidyverse)
library(triangle)
library(patchwork)
library(plotly)
plot_shaded_normal <- function(mean, sd, p = 0.5) {
shade_up_to_x <- qnorm(p, mean = mean, sd = sd)
data_normal <- data.frame(
x = seq(mean - 4 * sd, mean + 4 * sd, length.out = 300)
) |>
mutate(y = dnorm(x, mean = mean, sd = sd))
shaded_data_normal <- data_normal |>
filter(x <= shade_up_to_x)
ggplot(data_normal, aes(x = x, y = y)) +
geom_line() +
geom_area(
data = shaded_data_normal,
aes(x = x, y = y),
fill = "#ff8800",
alpha = 0.3
) +
geom_vline(xintercept = shade_up_to_x)
}
plot_shaded_triangle <- function(a, b, c = (a + b) / 2, p = 0.5) {
shade_up_to_x <- triangle::qtriangle(p, a = a, b = b, c = c)
data_tri <- data.frame(
x = seq(a, b, length.out = 300)
) |>
mutate(y = triangle::dtriangle(x, a = a, b = b, c = c))
shaded_data_tri <- data_tri |>
filter(x <= shade_up_to_x)
ggplot(data_tri, aes(x = x, y = y)) +
geom_line() +
geom_area(
data = shaded_data_tri,
aes(x = x, y = y),
fill = "#ff8800",
alpha = 0.3
) +
geom_vline(xintercept = shade_up_to_x)
}
plot_shaded_unif <- function(a = 0, b = 1, p = 0.5) {
shade_up_to_x <- qunif(p, min = a, max = b)
data_unif <- data.frame(
x = seq(a, b, length.out = 300)
) |>
mutate(y = dunif(x, min = a, max = b))
shaded_data_unif <- data_unif |>
filter(x <= shade_up_to_x)
ggplot(data_unif, aes(x = x, y = y)) +
geom_line() +
geom_area(
data = shaded_data_unif,
aes(x = x, y = y),
fill = "#ff8800",
alpha = 0.3
) +
geom_vline(xintercept = shade_up_to_x)
}
Reading paper:
Bai, J., So, K. C., Tang, C. S., Chen, X., & Wang, H. (2019). Coordinating supply and demand on an on-demand service platform with impatient customers. Manufacturing & Service Operations Management, 21(3), 556-570. https://doi.org/10.1287/msom.2018.0707
The slides used to be embedded… but they are too large to embed in this document anymore. A pdf version of the slides can be downloaded and viewed by clicking Here: Download Slides (PDF)